﻿using Cdx.Ui.App_Start;
using Cdx.Ui.Commands;
using Cdx.Ui.Models;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Cdx.Ui.Controllers
{
    public class MainController : Controller
    {        
        public ActionResult Index()
        {
            return View(Model.Instance);
        }

        public ActionResult MainPanel()
        {
            if (Model.Instance.CurrentUser == null)
            {
                CommandLoginBetaUser cmd = new CommandLoginBetaUser(Model.Instance);
                cmd.Execute();
            }

            return View(Model.Instance);        
        }
        
        public ActionResult CommandBar() 
        {
            return PartialView("CommandBar", null); 
        }

        public ActionResult UploadFile(HttpPostedFileBase file)
        {
            if (file == null)
            {
                return View(Model.Instance);
            }
            else
            {
                var command = new CommandCreateDocument(Model.Instance, Model.Instance.CurrentUser.Id, file);
                command.Execute();

                return RedirectToAction("Index");
            }
        }
    }
}
